//
//  HPSwiperFactory.h
//  HandPaySwiperModule
//
//  Created by marco on 14/12/4.
//  Copyright (c) 2014年 marco. All rights reserved.
//

#import <Foundation/Foundation.h>


extern const NSString* kSwiperSupportConfigSwipeCode;
#define swipeNameFromDef(_defineInDictionary) ((NSString*)[_defineInDictionary objectForKey:kSwiperSupportConfigSwipeCode]);


typedef NS_ENUM(NSInteger, HPPOSProcessType)
{
    HPPOSBusinessTypeBalance = 1,
    HPPOSBusinessTypeCollectMonety = 2,
    HPPOSBusinessTypeFastTransfer = 3,
    HPPOSBusinessTypeOther = 65535
};

@protocol HPSwiperContextDelegate
@required
-(void)choiseYourDevice:(NSArray*)devices;
-(void)swiperCsnDidChange:(NSString*)didChangeCsn;
@end


@class SwipeBindingInfo, HPBaseSwiper, POSProcess;
@protocol HPSwipeServiceProtocal;

@interface HPSwiperContext : NSObject
/**
 * when method 'swiperInstanceByType' invoke,
 * kvo will notify client object on property connectedDeviceCSN
 */
@property(nonatomic, readonly) NSString* connectedDeviceCSN;
/**
 * set data after 'lookupDeviceWithChannelName' be invoke.
 */
@property(nonatomic, readonly) NSArray*  supportDeviceDescriptions;
@property(nonatomic, readonly) id<HPSwipeServiceProtocal> avaliableService;
@property(nonatomic, readonly) NSDictionary* selectedSwiperDescription;

+(instancetype)sharedInstance;

-(void)addDelegate:(__weak id<HPSwiperContextDelegate>)delegate;
-(void)removeDelegate:(__weak id<HPSwiperContextDelegate>)delegate;
/**
 load SwiperType.plist from main bundle, 
 find the same set of definitions by 'channel' value and set to supportDeviceDescriptions property.
 it may be refactor to Asynchronous. recommend use KVO for receive load complete event
 @param cname: value define in SwiperType.plist file
 */
-(void)lookupDeviceWithChannelName:(NSString*)cname; // invoke load.
// the same info will get the same service.
-(POSProcess*)processorWithBindingInfo:(SwipeBindingInfo*)info businessType:(HPPOSProcessType)type; // TODO: complete it
// if the swiper thread is locked. retrun value is NO. else return YES
-(BOOL)setSelectedSwiperDescription:(NSDictionary*)swiperDescription;
-(void)clearContextAndFoceStopProcess;
@end


/*private*/
@interface HPSwiperContext(HPSwipeServiceFactory)
-(NSArray*)loadSwiperConfigPlistName:(NSString*)fileName bundle:(NSBundle*)bundle;
-(NSArray*)getDevicesFromPlistContent:(NSArray*)swiperArry channelName:(NSString*)cname;
-(HPBaseSwiper*)loadSwiperByDeviceDescription:(NSDictionary*)swiperDescription;
@end
